﻿using System.Web.Mvc;
using SeaBattle.Domain.Abstract.Services;
using SeaBattle.Domain.Factory;

namespace SeaBattle.Web.Controllers
{
    public class RoomController : Controller
    {
        private readonly IPlayerService _playerService;
        private readonly IGameService _gameService;

        public RoomController()
        {
            _playerService = PlayerFactory.PlayerService;
            _gameService = GameFactory.GameService;
        }

        public ActionResult Game(int id)
        {
            var game = _gameService.GetGameById(id);
            return View(game);
        }

        [HttpPost]
        public void Join(int id)
        {
            var game = _gameService.GetGameById(id);
            var player = _playerService.GetPlayer(User.Identity.Name);
            game.Opponent = player;
            game.BoardPreparing = true;
        }

        public ViewResult Opponent(int id)
        {
            var game = _gameService.GetGameById(id);
            return View(game);
        }
    }
}
